package it.polimi.TravelDream.ejb.eaos;

import it.polimi.TravelDream.ejb.dtos.AddressDTO;
import it.polimi.TravelDream.ejb.dtos.HotelDTO;
import it.polimi.TravelDream.ejb.entities.Address;
import it.polimi.TravelDream.ejb.entities.Hotel;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Session Bean implementation class HotelEAO
 */
@Stateless
public class HotelEAO implements HotelList {

	@PersistenceContext
	private EntityManager em;
	
    /**
     * Default constructor. 
     */
    public HotelEAO() {
    }
    
    @Override
    public void add(HotelDTO hotelDTO, AddressDTO addressDTO){
    	Address address = new Address(addressDTO);
    	em.persist(address);
    	em.persist(new Hotel(hotelDTO, address));
    }

}
